
package org.apache.dubbo.remoting;

import org.apache.dubbo.rpc.model.ScopeModel;
import org.apache.dubbo.rpc.model.ScopeModelUtil;

public class Dispatcher$Adaptive implements Dispatcher {
    public ChannelHandler dispatch(ChannelHandler handler, org.apache.dubbo.common.URL url) {

        String extName = url.getParameter("dispatcher",
                        url.getParameter("dispather",
                        url.getParameter("channel.handler", "all")));
        if (extName == null)
            throw new IllegalStateException("Failed to get extension (org.apache.dubbo.remoting.Dispatcher) name from url (" + url.toString() + ") use keys([dispatcher, dispather, channel.handler])");

        ScopeModel scopeModel = ScopeModelUtil.getOrDefault(url.getScopeModel(), Dispatcher.class);

        Dispatcher extension = (Dispatcher)
                scopeModel.getExtensionLoader(Dispatcher.class).getExtension(extName);

        return extension.dispatch(handler, url);
    }
}
